package com.cbgolf.oa.activity.statistics;

import android.os.Bundle;
import com.cbgolf.oa.R;
import com.cbgolf.oa.activity.BaseNewActivity;
import com.cbgolf.oa.contract.IStatisticsListDetailsContract.IStatisticsListDetailsPresenter;
import com.cbgolf.oa.contract.IStatisticsListDetailsContract.IStatisticsListDetailsView;
import com.cbgolf.oa.contract.IStatisticsListDetailsContract.IStatisticsListDetailsWaiter;
import com.cbgolf.oa.entity.ListBean;
import com.cbgolf.oa.event.EventStatistics;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.presenter.StatisticsListDetailsPresenterImp;
import com.cbgolf.oa.util.DataUtil;
import com.cbgolf.oa.views.StatisticsListDetailsViewImp;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 五种统计，单个详情查询
 *
 * @author lq
 * @date 2018/5/7
 */

public class StatisticsListDetailsActivity extends BaseNewActivity implements
    IStatisticsListDetailsWaiter {

  private IStatisticsListDetailsPresenter presenter;
  private IStatisticsListDetailsView view;

  private int mType;
  private ListBean mData;

  @Override
  public String getActivityTitle() {
    return "明细";
  }

  @Override
  public void back() {
    finish();
  }

  @Override
  protected int getLayoutId() {
    return R.layout.a_recycler_list;
  }

  @Override
  protected void init(Bundle savedInstanceState) {
    mType = DataUtil.getIntExtra(getIntent(), DataManager.KEY_TYPE, 0);
    mData = (ListBean) DataUtil.getSerializableExtra(getIntent(), DataManager.KEY_DATA);
    EventBus.getDefault().register(this);
    view = new StatisticsListDetailsViewImp(this, this, mType, mData);
    presenter = new StatisticsListDetailsPresenterImp(view);
    presenter.requestData(mType, DataUtil.INITDATA, mData);

  }


  @Override
  protected void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
  }

  @Subscribe(threadMode = ThreadMode.MAIN)
  public void requestOver(EventStatistics event) {
    view.requestOver(event);
  }

  @Override
  public void loadMore() {
    presenter.requestData(mType, DataUtil.LOADMORE, mData);
  }

  @Override
  public void refresh() {
    presenter.requestData(mType, DataUtil.REFRESH, mData);
  }
}
